namespace AdmissionQA.Domain.Entities;

/// <summary>
/// 问答历史记录实体
/// </summary>
public class QAHistory : EntityBase
{
    /// <summary>
    /// 用户查询文本
    /// </summary>
    public string Query { get; private set; }

    /// <summary>
    /// 系统回答
    /// </summary>
    public string Answer { get; private set; }

    /// <summary>
    /// 查询类型（常见问题、政策、专业、奖学金、校园生活、学费）
    /// </summary>
    public string QueryType { get; private set; }

    /// <summary>
    /// 置信度（高、中、低）
    /// </summary>
    public string Confidence { get; private set; }

    /// <summary>
    /// 用户IP地址（可选，用于分析）
    /// </summary>
    public string? UserIP { get; private set; }

    /// <summary>
    /// 用户代理（可选，用于分析）
    /// </summary>
    public string? UserAgent { get; private set; }

    /// <summary>
    /// 查询向量（用于后续分析）
    /// </summary>
    public float[]? QueryEmbedding { get; set; }

    /// <summary>
    /// 构造函数
    /// </summary>
    private QAHistory(string query, string answer, string queryType, string confidence, string? userIP = null, string? userAgent = null)
    {
        Query = query;
        Answer = answer;
        QueryType = queryType;
        Confidence = confidence;
        UserIP = userIP;
        UserAgent = userAgent;
    }

    /// <summary>
    /// 创建问答历史记录
    /// </summary>
    public static QAHistory CreateQAHistory(
        string query,
        string answer,
        string queryType,
        string confidence,
        string? userIP = null,
        string? userAgent = null)
    {
        if (string.IsNullOrWhiteSpace(query))
            throw new ArgumentException("查询文本不能为空", nameof(query));
        
        if (string.IsNullOrWhiteSpace(answer))
            throw new ArgumentException("回答不能为空", nameof(answer));
        
        if (string.IsNullOrWhiteSpace(queryType))
            throw new ArgumentException("查询类型不能为空", nameof(queryType));

        return new QAHistory(query, answer, queryType, confidence, userIP, userAgent);
    }

    /// <summary>
    /// 更新问答历史记录
    /// </summary>
    public void UpdateQAHistory(string newQuery, string newAnswer, string newQueryType, string newConfidence)
    {
        Query = newQuery;
        Answer = newAnswer;
        QueryType = newQueryType;
        Confidence = newConfidence;
        UpdatedAt = DateTime.UtcNow;
    }
} 